//
// Created by wdq on 22-9-18.
//
#include <iostream>

using namespace std;


void bubbleSort(int nums[], int length) {
    for (int i = 0; i < length - 1; i++) {
        bool isSorted = false;
        for (int j = 0; j < length - i - 1; j++) {
            if (nums[j] > nums[j + 1]) {
                isSorted = true;
                swap(nums[j], nums[j + 1]);
            }
        }
        if (!isSorted) {
            return;
        }
    }
}

int main() {

    int nums[] = {2, 6, 1, 56, 25, 67, 89, 5, 3, 3};
    printf("nums: ");
    for (auto &i: nums) {
        printf("%-4d ", i);
    }
    printf("\n");
    bubbleSort(nums, sizeof(nums) / sizeof(int));
    printf("sorting..........................\n");
    printf("nums: ");
    for (auto &i: nums) {
        printf("%-4d ", i);
    }
    printf("\n");
    return 0;
}